Completed
Push — master ( e88c19...17669b )
by Rain
03:00
created

Licensing.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 7 Features 0
Metric Value
cc 1
c 7
b 7
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A Licensing.js ➔ ... ➔ ??? 0 6 2
1
2
import ko from 'ko';
3
4
import {settingsGet} from 'Storage/Settings';
5
import {showScreenPopup} from 'Knoin/Knoin';
6
7
import LicenseStore from 'Stores/Admin/License';
8
9
import {getApp} from 'Helper/Apps/Admin';
10
11
class LicensingPremAdminSettings
12
{
13
	constructor() {
14
		this.licensing = LicenseStore.licensing;
15
		this.licensingProcess = LicenseStore.licensingProcess;
16
		this.licenseValid = LicenseStore.licenseValid;
17
		this.licenseExpired = LicenseStore.licenseExpired;
18
		this.licenseError = LicenseStore.licenseError;
19
		this.licenseTrigger = LicenseStore.licenseTrigger;
20
21
		this.adminDomain = ko.observable('');
22
		this.subscriptionEnabled = ko.observable(!!settingsGet('SubscriptionEnabled'));
23
24
		this.licenseTrigger.subscribe(() => {
25
			if (this.subscriptionEnabled())
26
			{
27
				getApp().reloadLicensing(true);
28
			}
29
		});
30
	}
31
32
	onBuild() {
33
		if (this.subscriptionEnabled())
34
		{
35
			getApp().reloadLicensing(false);
36
		}
37
	}
38
39
	onShow() {
40
		this.adminDomain(settingsGet('AdminDomain'));
41
	}
42
43
	showActivationForm() {
44
		showScreenPopup(require('View/Popup/Activate'));
45
	}
46
47
	showTrialForm() {
48
		showScreenPopup(require('View/Popup/Activate'), [true]);
49
	}
50
51
	/**
52
	 * @returns {boolean}
53
	 */
54
	licenseIsUnlim() {
55
		return 1898625600 === this.licenseExpired() || 1898625700 === this.licenseExpired(); // eslint-disable-line no-magic-numbers
56
	}
57
58
	/**
59
	 * @returns {string}
60
	 */
61
	licenseExpiredMomentValue() {
62
		const
63
			moment = require('moment'),
64
			time = this.licenseExpired(),
65
			momentUnix = moment.unix(time);
66
67
		return this.licenseIsUnlim() ? 'Never' : (time && (momentUnix.format('LL') + ' (' + momentUnix.from(moment()) + ')'));
68
	}
69
}
70
71
export {LicensingPremAdminSettings, LicensingPremAdminSettings as default};
72